package com.woniu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.entity.Expense;
import com.woniu.mapper.ExpenseMapper;
import com.woniu.service.IExpenseService;
import com.woniu.util.EmptyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hyl
 * @since 2022-08-28
 */
@Service
public class ExpenseServiceImpl extends ServiceImpl<ExpenseMapper, Expense> implements IExpenseService {

    @Autowired
    private ExpenseMapper expenseMapper;

    //查询全部
    @Override
    public List<Expense> getAll() {
        return expenseMapper.getAll();
    }

    //根据id查询
    public Expense getByExpId(int ExpId){
        return expenseMapper.getByExpID(ExpId);
    }
    //添加
    @Override
    public void addExp(String expCategory) {
//        if (expense != null && expense.getExpId()>0 &&expense.getExpCategory()!=null) {
//            expenseMapper.addExp(expense);
//        }

        if (!"".equals(expCategory)&&null!=expCategory){
            expenseMapper.addExp(expCategory);
        }
    }
    //修改
    @Override
    public void updateExp(Expense expense) {
        if (expense.getExpId()>0 && !"".equals(expense.getExpCategory())&&null!= expense.getExpCategory()){
            expenseMapper.updateExp(expense);
        }
    }

    @Override
    public List<Expense> getByCondition(Expense expense) {
        QueryWrapper<Expense> wrapper = new QueryWrapper<>();
        if (EmptyUtil.isNoEmpty(expense.getExpId())){
            System.out.println(expense.getExpId());
            wrapper.eq("exp_id",expense.getExpId());
        }

        return expenseMapper.getByCondition(wrapper);
    }


}
